Imports System.Windows.Forms

Public Class Options
  Private _templatePath As String = String.Empty

  Public Property TemplatePath() As String
    Get
      Return _templatePath
    End Get
    Set(ByVal value As String)
      _templatePath = value
    End Set
  End Property
  Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click

    If IO.Directory.Exists(Me.FolderPicker1.SelectedPath) = False Then
      Try
        IO.Directory.CreateDirectory(Me.FolderPicker1.SelectedPath)
        TemplatePath = Me.FolderPicker1.SelectedPath

      Catch ex As Exception
        MsgBox("There was an error creating new folder, " & Me.FolderPicker1.SelectedPath & vbCrLf & vbCrLf & "Error: " & ex.Message, , "Error Creating New Folder")
        Return

      End Try

    Else
      TemplatePath = Me.FolderPicker1.SelectedPath

    End If

    Me.DialogResult = System.Windows.Forms.DialogResult.OK
    Me.Close()

  End Sub

  Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
    Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
    Me.Close()

  End Sub

  Private Sub Options_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    My.Settings.OptionDialogLocation = Me.Location
    My.Settings.OptionDialogSize = Me.Size
    My.Settings.Save()

  End Sub

  Private Sub Options_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If My.Settings.OptionDialogLocation.Height > -1 Then
      Me.Location = My.Settings.OptionDialogLocation
    End If

    If My.Settings.OptionDialogSize.Height > -1 Then
      Me.Size = My.Settings.OptionDialogSize
    End If

    Me.FolderPicker1.SelectedPath = TemplatePath

  End Sub

  Private Sub OpenFolderLinkLabel_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles OpenFolderLinkLabel.LinkClicked
    If IO.Directory.Exists(Me.FolderPicker1.SelectedPath) Then
      Try
        Process.Start(Me.FolderPicker1.SelectedPath)
      Catch ex As Exception
        MsgBox("Error opening folder, " & Me.FolderPicker1.SelectedPath & vbCrLf & vbCrLf & "Error: " & ex.Message, , "Error Opening Folder")
      End Try

    Else
      MsgBox("The folder, " & Me.FolderPicker1.SelectedPath & " does not exist. This could be because new paths that are manually typed in will not be created until OK is clicked...", , "Folder Does Not Exist")
    End If

  End Sub

End Class
